<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Site extends CI_Controller {
	var $logged_in;
	public function __construct(){
		parent::__construct();
		// Your own constructor code
		$this->load->helper('url');	 // used for anchors
		$this->load->helper('form');
		
		// load required models
		$this->load->model('registration_model');
		$this->load->model('institutions_model');
		$this->load->model('users_model');
		$this->load->model('codes_model');
		
		$this->logged_in = $this->is_logged_in();
	}
	
	public function is_logged_in(){
		//print_r($this->session->userdata);
		
		$is_logged_in = $this->session->userdata('is_logged_in');
		
		if(!isset($is_logged_in) || $is_logged_in != true){
			/* not logged in.. redirect to login page */
			$data['main_content'] = 'login_view';
			$this->load->view('includes/template',$data);
			return false;
		}
		return true;
	}
	
	public function members_area(){
		$data['main_content'] = 'membersarea_view';
		$this->load->view('includes/template',$data);
	}
	
	public function add_institutions(){
		if($this->logged_in){
			$data['main_content'] = 'addinstitutions_view';
			$this->load->view('includes/template',$data);
		}
	}
	
	public function insert_institution(){
		if($this->logged_in){
			$this->institutions_model->add_new_institution();
			$data['main_content'] = 'aboutus_view';
			$this->view_institutions();
		}
	}
	
	public function view_institutions(){
		$data['instituions_list'] = $this->institutions_model->view_all_institutions();
		$data['main_content'] = 'viewinstitutions_view';
		$this->load->view('includes/template', $data);
	}
	
	public function add_users(){
		if($this->logged_in){
			$data['main_content'] = 'addusers_view';
			$this->load->view('includes/template',$data);
		}
	}

	public function view_users(){
		$data['users_list'] = $this->users_model->view_all_users();
		$data['main_content'] = 'viewusers_view';
		$this->load->view('includes/template', $data);
	}
	
	public function add_codetypes(){
		if($this->logged_in){
			$data['main_content'] = 'addcodetypes_view';
			$this->load->view('includes/template',$data);
		}
	}

	public function view_codetypes(){
		$data['codetypes_list'] = $this->codes_model->view_all_code_types();
		$data['main_content'] = 'viewcodetypes_view';
		$this->load->view('includes/template', $data);
	}
	
	public function insert_codetype(){
		if($this->logged_in){
			$this->codes_model->add_new_code_type();
			$this->view_codetypes();
		}
	}
	
	public function insert_user(){
		if($this->logged_in){
			$this->users_model->add_new_user();
			$this->view_users();
		}
	}
	
	/* coding systems start */
		public function add_codesystems(){
		if($this->logged_in){
			$data['main_content'] = 'addcodesystems_view';
			$data['codetypes_list'] = $this->codes_model->view_all_code_types();
			$this->load->view('includes/template',$data);
		}
	}

	public function view_codesystems(){
		$data['codesystems_list'] = $this->codes_model->view_all_code_systems();
		$data['main_content'] = 'viewcodesystems_view';
		$this->load->view('includes/template', $data);
	}
	
	public function insert_codesystem(){
		if($this->logged_in){
			$this->codes_model->add_new_code_system();
			$this->view_codesystems();
		}
	}
	/* coding systems end */
	
	/* coding components start */
	public function add_codecomponent(){
		if($this->logged_in){
			$data['main_content'] = 'addcodecomponents_view';
			$data['codesystems_list'] = $this->codes_model->view_all_code_systems();
			$this->load->view('includes/template',$data);
		}
	}

	public function view_codecomponents(){
		$data['codecomponents_list'] = $this->codes_model->view_all_code_components();
		$data['main_content'] = 'viewcodecomponents_view';
		$this->load->view('includes/template', $data);
	}
	
	public function insert_codecomponent(){
		if($this->logged_in){
			$this->codes_model->add_new_code_component();
			$this->view_codecomponents();
		}
	}
	/* coding components end */
	
}